cap cd "C:\Users\ejm5\Dropbox\PAPI conjoint\Replication"
cap cd "/Users/paulschuler/Dropbox/projects/PAPI conjoint/Replication"
use PAPI_Conjoint_3years.dta, clear
set more off
 
tab year
lab var party "Party Member"

mvdecode d101* d305* vote, mv(888=.b\999=.c)


#delimit;
label values a011 perform;
label define perform 0 "Very Bad" 1 "Bad" 2 "Neutral" 3"Good" 4"Very Good";


#delimit;
generate treatment_experience=1 if vote_exp !=.;
replace treatment_experience=0 if vote_job !=.;
lab var treatment_experience "Exposed to Candidates' Experience?";
label values treatment_experience experience;
label define experience 0 "No" 1 "Yes";

lab var no_policy "Exposed to Candidates' Policies?";
label values no_policy no_policy;
label define no_policy 0 "Policy Stated" 1 "No Policy";

lab var party "Candidate is Party Member";
label values party party;
label define party 0 "Non-Party" 1 "Party";

/**************************************************************************************************************************************/

/*Table 6: Triple Interaction Regression*/

#delimit;
svy: reg vote i.party i.no_policy i.treatment_experience age_39  male  bachelors masters doctorate  gov_nominee if year==2018;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata) replace;

#delimit;
svy: reg vote i.party##i.no_policy i.treatment_experience age_39 male  bachelors masters doctorate  gov_nominee if year==2018;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata);

#delimit;
svy: reg vote i.party##i.treatment_experience i.no_policy  age_39 male  bachelors masters doctorate  gov_nominee  if year==2018;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata);

#delimit;
svy: reg vote i.party##i.no_policy##i.treatment_experience age_39 male  bachelors masters doctorate  gov_nominee  if year==2018;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata);

#delimit;
svy: reg vote i.party i.no_policy i.treatment_experience age_39 male  bachelors masters doctorate  gov_nominee  if year==2018 & d101d5b==1;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata);


#delimit;
svy: reg vote i.party##i.no_policy i.treatment_experience age_39 male  bachelors masters doctorate  gov_nominee  if year==2018 & d101d5b==1;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata);

#delimit;
svy: reg vote i.party##i.treatment_experience i.no_policy  i.no_policy age_39 male  bachelors masters doctorate gov_nominee  if year==2018 & d101d5b==1;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata);


#delimit;
svy: reg vote i.party##i.no_policy##i.treatment_experience age_39 male  bachelors masters doctorate  gov_nominee  if year==2018 & d101d5b==1;
outreg2 using "Tables\Table6", tdec(3) bdec(3) e(rmse N_clust N_strata N_psu N_poststrata) excel;


/**************************************************************************************************************************************/

/*Figure 5: Conditional Marginal Means*/

#delimit;
svy: reg vote i.party##i.no_policy##i.treatment_experience age_39 age_59 male female high_school bachelors masters doctorate self_nominee gov_nominee if year==2018 & d101d5b==1, nocons;
margins party, atmeans at(no_policy=(0(1)1)) by(treatment_experience);

#delimit;
margins,  atmeans dydx(party)  over(treatment_experience no_policy )  level(95);
marginsplot, xdimension(treatment_experience) bydimension(no_policy) xlabel(, angle(45)) plotopts(connect(i) lcolor(navy) lwidth(thick) mcolor(purple) msymbol(diamond)) yline(0, lpattern(dash) lwidth(thick) lcolor(red)) scheme(s1color) ytitle("Conditional Marginal Mean of Party", size(medium) margin(medium)) title("");
graph save "Figures\cmm_nf.gph", replace;


#delimit;
svy: reg vote i.party##i.no_policy##i.treatment_experience age_39 age_59 male female high_school bachelors masters doctorate self_nominee gov_nominee if year==2018, nocons;
margins party, atmeans at(no_policy=(0(1)1)) by(treatment_experience);


#delimit;
margins,  atmeans dydx(party)  over(treatment_experience no_policy )  level(95);
marginsplot, xdimension(treatment_experience) bydimension(no_policy) xlabel(, angle(45)) plotopts(connect(i) lcolor(navy) lwidth(thick) mcolor(purple) msymbol(diamond)) yline(0, lpattern(dash) lwidth(thick) lcolor(red)) scheme(s1color) ytitle("Conditional Marginal Mean of Party", size(medium) margin(medium)) ylab(-.2(.2).4) title("");

graph save "Figures\cmm_f.gph", replace;

#delimit;
graph combine  "Figures\cmm_f.gph" "Figures\cmm_nf.gph", xcommon ycommon imargin(i) cols(2) note("Range bars=95% CI; All conjoint covariates included in regression. See Table X for full regression table.", size(vsmall) position(7) margin(medlarge)) scheme(s1color);
graph save "Figures\Figure5_cmm.gph", replace;
graph export "Figures\Figure5_cmm.pdf", replace;



/**************************************************************************************************************************************/
/*Figure 2 Research Design*/

#delimit;
 collapse no_policy treatment_experience exp_zero exp_y5 exp_y15 trade poverty growth environment if year==2018, by(respondent_id);
 drop if no_policy==.5;
 tab no_policy treatment_experience;
 
 #delimit;
lab var treatment_experience "Exposed to Candidates' Experience?";
label values treatment_experience experience2;
label define experience2 0 "Experience Unknown" 1 "Experience Known";

lab var no_policy "Exposed to Candidates' Policies?";
label values no_policy no_policy;
/*label define no_policy 0 "Policy Stated" 1 "No Policy";*/
#delimit;
graph bar (count), over(no_policy) over(treatment_experience) ytitle("Number of Respondents") note("Four treatment groups with each respondent evaluating two National Assembly candidates.", position(6) margin(medium)) scheme(s1color) bar(1, fcolor(bluishgray) lcolor(navy)) blabel(bar) ylab(0(500)4500, labsize(vsmall));
 graph save "Figures\Figure2_Design.gph", replace;
  graph export "Figures\Figure2_Design.pdf", replace;
